/* 
 * File:   ServerConfig.h
 * Author: dell
 *
 * Created on 2012年4月2日, 上午11:32
 */

#ifndef SERVERCONFIG_H
#define	SERVERCONFIG_H

#include <vector>
#include <string>
#include <ext/hash_map>

#include "../common.h"
#include "ContextConfig.h"
#include "EngineConfig.h"
#include "CacheConfig.h"
#include <evhttp/resources.h>

namespace Rapid{
    class ServerConfig {
    public:
        ServerConfig();
        virtual ~ServerConfig();

        int port;   
        int workerCount; 
        int requestBufferSize;
        int responseBufferSize; 
        int requestLineMaxBytes;
        double timeout;  
        int poolMaxHandlerCount;

        typedef hash_map<const char*, ContextConfig*, hash<const char*>, HashMapStrIgnoreCaseCompare> ContextConfigMap;
        ContextConfigMap contextConfigMap;

        /**
        * 如果未配置engine节点，将使用默认DefaultHttpEngine
        */
        EngineConfig engineConfig;
        /** 指示是否存在EngineConfig配置, 默认为:flase */
        bool existEngineConfig;

        /**
         * 文件缓存配置
         */
        CacheConfig cacheConfig;
        
        void debug(){
            LOG_DEBUG("port:%d", port);
            LOG_DEBUG("workerCount:%d", workerCount);
            LOG_DEBUG("requestBufferSize:%d", requestBufferSize);
            LOG_DEBUG("responseBufferSize:%d", responseBufferSize);
            LOG_DEBUG("requestLineMaxBytes:%d", requestLineMaxBytes);
            LOG_DEBUG("timeout:%f", timeout);
            LOG_DEBUG("poolMaxHandlerCount:%d", poolMaxHandlerCount);

            LOG_DEBUG("existEngineConfig:%s", (existEngineConfig?"true":"false"));
            if(existEngineConfig)engineConfig.debug();
            cacheConfig.debug();

            ContextConfigMap::iterator cxtit = contextConfigMap.begin();
            for(; cxtit != contextConfigMap.end(); cxtit++){
                ContextConfig* contextConfig = cxtit->second;
                contextConfig->debug();
            }

        }



    };

}
#endif	/* SERVERCONFIG_H */
